home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Tele / T / Telebit.cpt / New Telebit Modem next >
Text File  |  1988-07-06  |  23KB  |  701 lines

  1. '                    ################################
  2. '                    ## TELEBIT MODEM SERVICE FILE ##
  3. '                    ################################
  4.  
  5.  
  6. ' Written by Lloyd Kreuzer, Kreuzer Software Corp.
  7. ' Revision, editing, and additions by Ken Walter
  8. ' TELEBIT modifications by Mike Smith, 6/20/88
  9.  
  10. ' Last Modified 7/6/88
  11.  
  12. ' Contains Identify, Dial, Configure, HangUp, ClearTable, and Interrupt routines
  13. ' for Hayes and Hayes-compatible modems
  14.     
  15. '********************************************************************************
  16. Identify:   ' This routine tells calling file that this is a modem file
  17. '********************************************************************************
  18.     Message = "MODEM"
  19.     RETURN
  20.  
  21. '********************************************************************************
  22. Dial:       ' Inits modem, dials a number and tries to get on-line
  23. '********************************************************************************
  24.  
  25. ' Enter with phone numbers and modem settings in the system variable Message
  26. ' Each number and modem settings pair is separated by a ":"
  27. ' The number and modem settings are separated by "|".
  28. ' If there are no settings don't use a "|".
  29. ' No colon after last number
  30. ' For example:  Message = "555-1212|1200,8,NO%,1,YES%:987-6543|2400,8,NO%,1,YES%"
  31.     HOLD ON                         ' for speed and no interrupts
  32.  
  33.     ' If service set @modemRedial%, set it to false and use next number in
  34.     ' @modemNumbers, if @modemNumbers is not NIL, else use Message
  35.     IF @modemRedial% THEN ∂
  36.         @modemRedial% = FALSE%: ∂
  37.         IF @modemNumbers <> "" THEN Message = @modemNumbers
  38.     IF Message = "" THEN Message = "Dial called without a phone number.":RETURN
  39.     @modemNumbers = Message
  40.     ' configure modem if necessary (@modemMaxBPS% is set if modem was configured)
  41.     IF @modemMaxBPS% = 0 THEN GOSUB Configure:HOLD ON
  42.     ' init modem command strings
  43.     GOSUB quickModemCommands
  44.  
  45.     ' reset and initialize modem
  46.     GOSUB modemReset
  47. dial1:
  48.  
  49.     HOLD ON
  50.     CURSOR PHONE
  51.  
  52.     ' parse next number/settings pair from @modemNumbers
  53.     ' find the colon
  54.     modemColon% = InStr%(@modemNumbers, ":")
  55.     ' put first pair in modemPhoneNumber
  56.     ' and, if there is a colon, put remaining numbers in @modemNumbers
  57.     IF modemColon% <> 0 THEN ∂
  58.         modemPhoneNumber = Left(@modemNumbers,(modemColon%-1)): ∂
  59.         @modemNumbers = Mid(@modemNumbers,(modemColon%+1)) ∂
  60.     ELSE ∂
  61.         modemPhoneNumber = @modemNumbers: ∂
  62.         @modemNumbers = ""
  63.     ' find the start of the settings string, if any
  64.     modemBar% = InStr%(modemPhoneNumber,"|")
  65.     ' separate settings from phone number and set default settings if no settings
  66.     IF modemBar% <> 0 THEN ∂
  67.         modemParams = Mid(modemPhoneNumber,(modemBar%+1)) : ∂
  68.         modemPhoneNumber = Left(modemPhoneNumber,(modemBar%-1)) ∂
  69.     ELSE modemParams = ""
  70.  
  71.     ' if we're out of phone numbers, then return
  72.     IF modemPhoneNumber = "" THEN ∂
  73.         Status = "Off Line": ∂
  74.         Message = "No Carrier.": ∂
  75.         CommC.RemEcho% = SaveRemEcho%: ∂    ' restore changed settings
  76.         CommC.DBits% = SaveDBits%: ∂
  77.         HOLD OFF: ∂
  78.         RETURN
  79.  
  80.     'HOLD OFF
  81.  
  82.     ' set communications settings to settings passed in Message, if any
  83.     'For TELEBIT strip BPS off front and prefix with "19200" instead
  84.     'Also set xmitMode string to force PEP mode if in "Universal" mode and BPS >= 9600
  85.     xmitMode = ""   'Default is to leave s50 register alone
  86.     IF modemParams <> "" THEN ∂
  87.         requestedBPS% = val%(modemParams): ∂
  88.         modemParams = mid(modemParams, instr%(modemParams, ",")): ∂
  89.         modemParams = "19200" & modemParams: ∂
  90.         SET modemParams: ∂
  91.         if @modemInit = @modemInitUniv then ∂
  92.             if requestedBPS% >= 9600 then xmitMode = "255" ∂
  93.             else xmitMode = "0"
  94.  
  95.     'HOLD ON
  96.  
  97.     ' Set up look-fors for carrier detect and errors
  98.  
  99.     ' If 3 string then try the next number
  100.     LOOK FOR "3" & modemCommEnd,1,1 THEN ∂
  101.         CLEAR DBOX 500: ∂
  102.         GOTO dial1                  ' try next number
  103.  
  104.     ' If there is an error then tell user
  105.     LOOK FOR "4" & modemCommEnd,1,1 THEN ∂
  106.         CLEAR DBOX 500: ∂
  107.         Message = "Modem dial command error.  " ∂
  108.             & "Please check phone number(s) and command strings and try again.": ∂
  109.         GOSUB modemFatalError: ∂
  110.         CURSOR PHONE: ∂
  111.         GOTO reDial                 ' Try again with same number
  112.  
  113.     ' Look for busy string (if any) and try next number
  114.     LOOK FOR "7" & modemCommEnd,1,1 THEN ∂
  115.         CLEAR DBOX 500: ∂
  116.         Status = "Busy": ∂
  117.         GOSUB quickHangUp: ∂
  118.         GOTO dial1              ' try next number
  119.  
  120.     LOOK FOR "50^M",1,3 THEN HOLD ON:GOTO carrierPEP    'CONNECT FAST
  121.     LOOK FOR "10^M",1,3 THEN HOLD ON:GOTO carrierHayes  'CONNECT 2400
  122.     LOOK FOR "5^M", 1,3 THEN HOLD ON:GOTO carrierHayes  'CONNECT 1200
  123.     LOOK FOR "1^M", 1,3 THEN HOLD ON:GOTO carrierHayes  'CONNECT 300
  124.  
  125. reDial:
  126.     Status ="Dialing"
  127.     SET DBOX 500
  128.     ButtonText(2) = "Now calling " & modemPhoneNumber & "."
  129.     HOLD OFF
  130.     
  131.     ' set Transmission Mode
  132.     if xmitMode <> "" then ∂
  133.         send "at s50="; xmitMode: ∂
  134.         wait for "0" for 2
  135.  
  136.     ' dial the number
  137.     
  138.     '{RTV 7/6/88}
  139.     IDLE 60
  140.     
  141.     SEND @modemDialPre; modemPhoneNumber
  142.  
  143.     DBOX 500            ' Wait for look-fors or user cancel
  144.     
  145. '{RTV 5/11/88}
  146. waitWhileDialing:
  147.     IF DBoxResult% <> OK% THEN GOTO waitWhileDialing
  148.     
  149.     HOLD ON             ' User clicked "Cancel" button, so hang up and end
  150.     CLEAR DBOX 500
  151.     FORGET ALL
  152.     Message = ""
  153.     GOSUB quickHangUp
  154.     CommC.RemEcho% = SaveRemEcho%       ' restore changed settings
  155.     CommC.DBits% = SaveDBits%
  156.     END
  157.  
  158. 'If Fast XModem is checked and answered as CONNECT FAST then change to CRC XModem
  159. 'This is needed because TELEBIT's XModem spoof only works with 128 byte blocks
  160. 'If a Hayes is at other end and Fast XModem is checked then put back to 1K blocks XModem
  161. 'If FastXModem is not checked or TELEBIT to Hayes in selected then protocol is never changed
  162. carrierPEP:
  163.     if (@modemMaxBPS% >= 9600) and @modemFastXModem% then ∂
  164.         CommC.ProtOpt% = 1
  165.     goto carrier
  166.     
  167. carrierHayes:
  168.     if (@modemMaxBPS% < 9600) and @modemFastXModem% then ∂
  169.         CommC.ProtOpt% = 2
  170.  
  171. carrier:                                'carrier detected
  172.     CLEAR DBOX 500
  173.     TIMER RESET
  174.     TIMER START
  175.     CURSOR RESET
  176.     Status = "On Line"
  177.     PhoneNum = modemPhoneNumber
  178.     CommC.RemEcho% = SaveRemEcho%       ' restore changed settings
  179.     CommC.DBits% = SaveDBits%
  180.     FORGET ALL
  181.     HOLD OFF
  182.     RETURN
  183.  
  184. '****************************************************************************
  185. HangUp:
  186. '****************************************************************************
  187. ' This routine hangs up the phone line and resets the modem
  188. ' It is normally called when the modem is on line but it can be
  189. ' called with the modem off line. In either case it will return
  190. ' with Message = "" and Status = "Off Line"
  191. ' if everything is OK or else produce a fatal error
  192.  
  193.     HOLD ON                 ' for speed
  194.     STATUS = "Hanging Up"
  195.     IF @modemMaxBPS% = 0 THEN GOSUB configure
  196.     GOSUB quickHangUpCommands
  197.  
  198. quickHangUp:        ' come here if command strings are inited
  199.     CURSOR PHONE
  200.     FORGET OFF
  201.  
  202.     LOOK FOR "4" & modemCommEnd,1,1 THEN ∂
  203.         Message = "Invalid modem command string.":∂
  204.         GOSUB modemFatalError:∂
  205.         GOTO quickHangUp        ' try again
  206.  
  207.     LOOK FOR "0" & modemCommEnd,1,1 THEN ∂
  208.         IF modemHangUp% = FALSE% THEN WAIT 1:GOTO hangUp2 ∂
  209.         ELSE ∂
  210.             FORGET ALL:∂
  211.             FORGET ON: ∂
  212.             Status = "Off Line":∂
  213.             TIMER STOP:∂
  214.             CURSOR RESET:∂
  215.             Message = "" :∂
  216.             CommC.RemEcho% = SaveRemEcho%: ∂    ' restore changed settings
  217.             CommC.DBits% = SaveDBits%: ∂
  218.             RETURN
  219.  
  220.     hangUpTries% = 1
  221.  
  222.     HOLD OFF
  223.  
  224. hangUp1:
  225.  
  226.     WAIT 1                      'This is needed for TELEBIT,
  227.     IDLE 60 FOR 4
  228.     SEND "+++";                 ' send escape
  229.     modemHangUp% = FALSE%
  230.     WAIT 1
  231.  
  232. hangUp2:    ' send hang up string
  233.  
  234.     modemHangUp% = TRUE%
  235.     IDLE 60       ' pause
  236.     SEND "ATH0"
  237.     WAIT 1            ' wait for look-fors
  238.  
  239.     HOLD ON
  240.     ' reset modem if hangup won't work
  241.     ' init modem command strings needed for reset
  242.     GOSUB quickModemCommands
  243.     GOSUB modemReset
  244.     Status = "Off Line"             ' will return only if reset is successful
  245.     Message = ""
  246.     CommC.RemEcho% = SaveRemEcho%   ' restore changed settings
  247.     CommC.DBits% = SaveDBits%
  248.     TIMER STOP
  249.     CURSOR RESET
  250.     HOLD OFF
  251.     RETURN
  252.  
  253. '****************************************************************************
  254. AutoAnswer:     ' This routine puts the modem in autoanswer mode.
  255. '****************************************************************************
  256.  
  257.     HOLD ON
  258.     CURSOR PHONE
  259.     IF @modemMaxBPS% = 0 THEN GOSUB configure
  260.     GOSUB quickModemCommands    'Initialize variables
  261.  
  262.     ' Parse Message into modemAnswerRings and answerWait
  263.     ' modemAnswerRings = number of rings modem waits before answering (Default is 1)
  264.     ' modemAnswerWait = time modem waits for call (default is forever)
  265.     GOSUB parseAnswerMessage
  266.     answerWait% = VAL%(answerWait)
  267.  
  268. reAnswer:
  269.  
  270.     'reset and initialize modem
  271.     GOSUB modemReset
  272.  
  273.     HOLD ON
  274.     CURSOR PHONE
  275.     STATUS = "Auto-Answer Set-up"
  276.     ' set up look-fors for auto-answer commands
  277.         
  278. '{RTV - 5/13/88  A Ring (2) may affect where the LOOK FOR is. Change to 1,5 vs. 1,1}
  279. '{RTV - 7/6/88 Who knows where the cur pos will be - columns deleted}
  280.     'LOOK FOR "4" & modemCommEnd,1,5 THEN ∂
  281.     LOOK FOR "4" & modemCommEnd THEN ∂
  282.         FORGET ALL: ∂
  283.         Message = "Invalid modem command string.": ∂
  284.         GOSUB modemFatalError: ∂
  285.         GOTO reAnswer
  286.         
  287. '{RTV - 5/13/88  A Ring (2) may affect where the LOOK FOR is. Change to 1,5 vs. 1,1}
  288. '{RTV - 7/6/88 Who knows where the cur pos will be - columns deleted}
  289.     'LOOK FOR "0" & modemCommEnd,1,5 THEN ∂
  290.     LOOK FOR "0" & modemCommEnd THEN ∂
  291.         FORGET ALL: ∂
  292.         HOLD ON: ∂
  293.         GOTO autoAnswerLookfors
  294.         
  295.     HOLD OFF
  296.     
  297.     '{RTV 7/6/88}
  298.     IDLE 60
  299.     
  300.     SEND "ATS0="; modemAnswerRings
  301.     WAIT 2        ' wait for look-fors (error or OK)
  302.     Message = "Unable to set auto-answer mode."
  303.     GOSUB modemFatalError
  304.     GOTO reAnswer
  305.  
  306. autoAnswerLookfors:
  307.     ' wait for a connect strings and set bps to that of calling computer
  308.     FORGET ALL
  309.     ' If 3 then go back to auto-answer mode for until time-out or autoanswer
  310.     LOOK FOR "3" & modemCommEnd,1,1 THEN ∂
  311.         FORGET ALL: ∂
  312.         CLEAR DBOX 499: ∂
  313.         answerWait% = endTime% - Now%: ∂
  314.         GOTO reAnswer
  315.  
  316.     LOOK FOR "4" & modemCommEnd  THEN ∂
  317.         FORGET ALL: ∂
  318.         CLEAR DBOX 499: ∂
  319.         Message = "Modem dial command error.":∂
  320.         GOSUB modemFatalError:∂
  321.         GOTO reAnswer
  322.  
  323.     ' set up look fors for carrier according to maximum modem speed
  324.     modemGoto% = @modemMaxBPS% + 2
  325.     GOTO modemGoto%
  326.  
  327.     19202:  LOOK FOR "50^M",1,3 THEN HOLD ON:GOTO leaveAnswerPEP    'CONNECT FAST
  328.     2402:   LOOK FOR "10^M",1,3 THEN HOLD ON:GOTO leaveAnswerHayes  'CONNECT 2400
  329.     1202:   LOOK FOR "5^M", 1,3 THEN HOLD ON:GOTO leaveAnswerHayes  'CONNECT 1200
  330.     302:    LOOK FOR "1^M", 1,3 THEN HOLD ON:GOTO leaveAnswerHayes  'CONNECT 300
  331.  
  332. autoAnswer2:
  333.     Status = "Waiting for Call"
  334.     TIMER RESET
  335.     TIMER START
  336.     endTime% = Now% + answerWait%
  337.     HOLD OFF
  338.     SET DBOX 499
  339.     DBOX 499
  340. waitForCalls:   ' Wait for call, user cancel, or time out
  341.  
  342. '{RTV 5/11/88}
  343.     IF (Now% > endTime%) AND (answerWait% <> -1) THEN GOTO answerTimeOut
  344.     
  345.     IF DBoxResult% <> OK% THEN GOTO waitForCalls
  346.     CLEAR DBOX 499  'User clicked "Cancel" button
  347.  
  348. '{RTV - 5/17/88 - In case modem answered while clearing DBOX 499}
  349.     GOSUB HangUp
  350.     
  351.     SEND "ATS0=0"
  352.     Message = "CANCEL"
  353.     Status = "Off Line"
  354.     TIMER STOP
  355.     TIMER RESET
  356.     CURSOR RESET
  357.     FORGET ALL
  358.     CommC.RemEcho% = SaveRemEcho%   ' restore changed settings
  359.     CommC.DBits% = SaveDBits%
  360.     RETURN
  361.  
  362. answerTimeOut:
  363.     CLEAR DBOX 499
  364.  
  365. '{RTV - 5/17/88 - In case modem answered while we weren't looking}
  366.     GOSUB HangUp
  367.     
  368.     SEND "ATS0=0"
  369.     Message = "TIMEOUT"
  370.     Status = "Off Line"
  371.     TIMER STOP
  372.     TIMER RESET
  373.     CURSOR RESET
  374.     FORGET ALL
  375.     CommC.RemEcho% = SaveRemEcho%   ' restore changed settings
  376.     CommC.DBits% = SaveDBits%
  377.     RETURN
  378.  
  379. 'If Fast XModem is checked and answered as CONNECT FAST then change to CRC XModem
  380. 'This is needed because TELEBIT's XModem spoof only works with 128 byte blocks
  381. 'If a Hayes is at other end and Fast XModem is checked then put back to 1K blocks XModem
  382. 'If FastXModem is not checked or TELEBIT to Hayes in selected then protocol is never changed
  383. leaveAnswerPEP:
  384.     if (@modemMaxBPS% >= 9600) and @modemFastXModem% then ∂
  385.         CommC.ProtOpt% = 1
  386.     goto leaveAnswer
  387.     
  388. leaveAnswerHayes:
  389.     if (@modemMaxBPS% < 9600) and @modemFastXModem% then ∂
  390.         CommC.ProtOpt% = 2
  391.  
  392. leaveAnswer:
  393.     CLEAR DBOX 499
  394.     Status = "On Line"
  395.     TIMER RESET
  396.     TIMER START
  397.     CURSOR RESET
  398.     FORGET ALL
  399.     CommC.RemEcho% = SaveRemEcho%   ' restore changed settings
  400.     CommC.DBits% = SaveDBits%
  401.     HOLD OFF
  402.     RETURN
  403.  
  404. '*******************************************************************************
  405. Configure:      'get modem configuration and store in lookup table
  406. '*******************************************************************************
  407.  
  408.     HOLD ON
  409.     CURSOR WATCH
  410.     
  411.     'Define default init strings
  412.     '{RTV 7/6/88 Added S7=40 to InitHayes}
  413.     InitHayes = "at v0 h0 s0=0 s7=40 s50=3 s54=3 s58=2"
  414.     InitPEP   = "at v0 h0 s0=0 s7=60 s50=255 s54=3 s58=2"
  415.     InitUniv  = "at v0 h0 s0=0 s7=60 s50=0 s54=3 s58=2 s92=1"
  416.     
  417.     'Set defaults for undefined lookup table items
  418.     if @modemMaxBPS% = 0 then @modemMaxBPS% = 19200
  419.     if @modemInitHayes = "" then @modemInitHayes = InitHayes
  420.     if @modemInitPEP   = "" then @modemInitPEP   = InitPEP
  421.     if @modemInitUniv  = "" then ∂
  422.         @modemInitUniv  = InitUniv: ∂
  423.         @modemFastXModem% = TRUE%                       ' assume first TELEBIT run
  424.     
  425.     SET DBOX 240                                        ' modem configure  dbox
  426.     IF @modemMaxBPS% = 19200 THEN ∂
  427.         RadioCluster%(1) = 2: ∂
  428.         @modemInit = @modemInitPEP ∂
  429.     ELSE IF @modemMaxBPS% = 9600 THEN ∂
  430.         RadioCluster%(1) = 3: ∂
  431.         @modemInit = @modemInitUniv ∂
  432.     ELSE ∂
  433.         RadioCluster%(1) = 1: ∂
  434.         @modemInit = @modemInitHayes
  435.         
  436.     DboxResp(1) = @modemInit
  437.     
  438.     
  439.     'Save RadioCluster%(1)'s original setting to see if user changes it
  440.      originalRC1% = RadioCluster%(1)
  441.    
  442.     CheckBox%(1) = @modemCompression%
  443.     CheckBox%(2) = @modemFastXModem%
  444.     CheckBox%(3) = (UpCase(@modemDialPre) = "ATDT")
  445.     
  446.     'Save user-entered text into temp strings in case CANCEL is pressed
  447.     'Initialize temporary strings here
  448.     TempHayes = @modemInitHayes
  449.     TempPEP = @modemInitPEP
  450.     TempUniv = @modemInitUniv
  451.     
  452.     HOLD OFF
  453.     DBoxLoop:
  454.         DBOX 240
  455.         HOLD ON
  456.         IF originalRC1% <> RadioCluster%(1) THEN gosub UpdateDBox
  457.         IF DBoxResp(1) = "" then ∂
  458.             BELL:∂
  459.             IF RadioCluster%(1) = 1 THEN DBoxResp(1) = InitHayes ∂
  460.             ELSE IF RadioCluster%(1) = 2 THEN DBoxResp(1) = InitPEP ∂
  461.             ELSE DBoxResp(1) = InitUniv
  462.         HOLD OFF
  463.         dbr% = DBoxResult%
  464.         IF dbr% = CANCEL% THEN CLEAR DBOX 240: END    'user selected CANCEL
  465.         IF dbr% <> OK% THEN goto DBoxLoop
  466.     HOLD ON
  467.     CURSOR WATCH
  468.     
  469.     IF originalRC1% = RadioCluster%(1) THEN gosub UpdateDBox
  470.     
  471.     IF RadioCluster%(1) = 1 THEN ∂
  472.         @modemMaxBPS% = 2400: ∂
  473.         @modemInit = TempHayes ∂
  474.     ELSE IF RadioCluster%(1) = 2 THEN ∂
  475.         @modemMaxBPS% = 19200: ∂
  476.         @modemInit = TempPEP ∂
  477.     ELSE ∂
  478.         @modemMaxBPS% = 9600: ∂
  479.         @modemInit = TempUniv
  480.     
  481.     'Write temporary strings back to lookup table
  482.     @modemInitHayes = TempHayes
  483.     @modemInitPEP = TempPEP
  484.     @modemInitUniv = TempUniv
  485.  
  486.     @modemCompression% = CheckBox%(1)
  487.     @modemFastXModem% = CheckBox%(2)
  488.     IF CheckBox%(3) THEN @modemDialPre = "ATDT" ELSE @modemDialPre = "ATDP"
  489.     
  490.     CLEAR DBOX 240
  491.     CURSOR RESET
  492.     HOLD OFF
  493.     RETURN
  494.  
  495. UpdateDBox:
  496.     IF originalRC1% = 1 THEN TempHayes = DBoxResp(1) ∂
  497.     ELSE IF originalRC1% = 2 THEN TempPEP = DBoxResp(1) ∂
  498.     ELSE TempUniv = DBoxResp(1) ∂
  499.     
  500.     IF RadioCluster%(1) = 1 THEN DBoxResp(1) = TempHayes ∂
  501.     ELSE IF RadioCluster%(1) = 2 THEN DBoxResp(1) = TempPEP ∂
  502.     ELSE DBoxResp(1) = TempUniv
  503.     
  504.     originalRC1% = RadioCluster%(1)
  505.     RETURN
  506.  
  507.  
  508. ClearTable:             'clear all modem values from the lookup table
  509.     CLEAR @modemCustom% 'clear out old Hayes vars too just to keep table clean
  510.     CLEAR @modemMaxBPS%
  511.     CLEAR @modemDialPre
  512.     CLEAR @modemNumbers
  513.     CLEAR @modemRedial%
  514.     CLEAR @modemCommEnd%
  515.     CLEAR @modemCommEnd
  516.     CLEAR @modemEscape
  517.     CLEAR @modemGuardTime%
  518.     CLEAR @modemInit
  519.     CLEAR @modemInitHayes
  520.     CLEAR @modemInitPEP
  521.     CLEAR @modemInitUniv
  522.     CLEAR @modemHangUp
  523.     CLEAR @modemNoCarrier
  524.     CLEAR @modemBusy
  525.     CLEAR @modemCommAck
  526.     CLEAR @modemCommError
  527.     CLEAR @modemCompression%
  528.     CLEAR @modemFastXModem%
  529.     RETURN
  530.  
  531. '****************************************************************************
  532. 'Internal subroutines from this point to end of file
  533. 'These subroutines should not be called directly from an external program
  534. '****************************************************************************
  535.  
  536. modemReset:     'Reset the modem and send the init string to the modem
  537.  
  538.     HOLD OFF
  539.     if version% < 16809985 then ∂
  540.         dboxSay = "Sorry, the TELEBIT modem file will not work with older versions of Acknowledge.": ∂
  541.         dbox: ∂
  542.         end
  543.     IF (@modemMaxBPS% = 0) or (@modemInit = "") THEN GOSUB Configure
  544.     CURSOR PHONE
  545.     Status = "Resetting Modem"
  546.     CommC.DTR% = TRUE%
  547.     CommC.CTS% = TRUE%
  548.     
  549.     'Compose modem initialization string
  550.     modemInit = @modemInit
  551.     if @modemMaxBPS% < 9600 then goto NoTelebitStuff
  552.         if @modemCompression% then modemInit = modemInit & "s110=1"
  553.         if @modemFastXModem% then modemInit = modemInit & "s111=20"
  554.     NoTelebitStuff:
  555.  
  556.     resetTries% = 0             'Reset number of retries count
  557.     
  558. modemReset1:
  559.     gosub SetupLookfors         'Setup LOOK FOR "OK" and LOOK FOR "ERROR"
  560.     send modemInit              'If we're lucky, one of the LOOK FOR's will hit
  561.     
  562.     idle 60
  563.     forget all
  564.     
  565.     '{RTV 7/6/88}
  566.     'look for "0^M", 1, 5 then ∂
  567.         'gosub SetupLookfors: ∂
  568.         'send modemInit: ∂
  569.         'wait 1: ∂
  570.         'goto FindBaud
  571.         
  572.     send "+++";                 'we weren't so lucky.  Enter command state...
  573.     wait 1
  574.     
  575.     '{RTV 7/6/88}
  576.     GOSUB SetupLookfors
  577.     SEND modemInit              'and try again.  If we blow it here, then we'll have to
  578.     WAIT 1                      'check the modem's baud
  579.  
  580. FindBaud:
  581.     'Still not responding, get Telebit set to a known baud rate
  582.     forget all
  583.     s = "^M^Mat &f v1"
  584.     look for "OK^M^J" then goto BaudFound
  585.     bps% = 19200: CommC.BPS% = bps%: send s: wait 1
  586.     bps% = 9600:  CommC.BPS% = bps%: send s: wait 1
  587.     bps% = 2400:  CommC.BPS% = bps%: send s: wait 1
  588.     bps% = 1200:  CommC.BPS% = bps%: send s: wait 1
  589.     bps% = 300:   CommC.BPS% = bps%: send s: wait 1
  590.     goto resetAgain                 'Maybe RING RING is comming in, try again
  591.  
  592. BaudFound:
  593.     forget all
  594.     CommC.BPS% = 9600
  595.     idle 20
  596.     send "at s66=1 s51=5"           'Set modem to start up at 19200 (set s66 before s51!)
  597.     idle 20                         'Wait for things to settle
  598.     CommC.BPS% = 19200              'Set Macintosh BPS to 19200
  599.     idle 20
  600.     SEND "at s66=1 s51=5"           'Set modem to start up at 19200 AGAIN
  601.     IDLE 20                         'just in case we're connected (don't ask!)
  602.     send "at &W"                    'Write settings to parameter RAM
  603.     idle 20
  604.     
  605. resetAgain:                         'Try 5 times
  606.     resetTries% = resetTries% + 1
  607.     IF resetTries% < 5 THEN GOTO modemReset1 ∂
  608.     ELSE Message = "Modem not responding. Try turning modem power on and off." &∂
  609.         "  Check modem connections.": ∂
  610.         GOSUB modemFatalError: ∂
  611.         GOTO modemReset
  612.  
  613. SetupLookfors:
  614.     '{RTV - 5/13/88  A Ring (2) may affect where the LOOK FOR is. Change to 1,5 vs. 1,1}
  615.     LOOK FOR "4^M",1,5 THEN ∂
  616.         Message = "Invalid modem command string." & ∂
  617.             "Please check phone number(s) and command strings and try again.": ∂
  618.         GOSUB modemFatalError:∂
  619.         GOTO modemReset
  620.         
  621.     '{RTV - 5/13/88  A Ring (2) may affect where the LOOK FOR is. Change to 1,5 vs. 1,1}
  622.     LOOK FOR "0^M",1,5 THEN HOLD ON: ∂
  623.         Release: clreol: Message = "":FORGET ALL:FORGET ON:RETURN
  624.     RETURN
  625.  
  626. quickModemCommands:             ' come here for non-custom modems
  627.     IF @modemMaxBPS% = 19200 THEN @modemInit = @modemInitPEP ∂
  628.     ELSE IF @modemMaxBPS% = 9600 THEN @modemInit = @modemInitUniv ∂
  629.     ELSE @modemInit = @modemInitHayes
  630.         
  631. quickHangUpCommands:            ' for hanging up we don't need above variables
  632.  
  633.     ' save any comm settings that are changed
  634.     SaveRemEcho% = CommC.RemEcho%
  635.     SaveDBits% = CommC.DBits%
  636.  
  637.     ' Reset echo and dbits so that commands will work
  638.     CommC.RemEcho% = NO%
  639.     CommC.DBits% = 8
  640.  
  641.     modemCommEnd = chr(13)
  642.     RETURN
  643.  
  644. parseAnswerMessage:
  645.     'Parses Message into modemAnswerRings and answerWait
  646.     modemAnswerRings = Message
  647.     answerWait = "-1" 'answerWait% = -1 if no value passed (so we wait forever)
  648.  
  649.     ' parse the node address into nodeAddress
  650.     messageLine% = INSTR%(Message,"|")
  651.     IF messageLine% <> 0 THEN ∂
  652.         modemAnswerRings = LEFT(Message, messageLine% - 1): ∂
  653.         answerWait = MID(Message, messageLine% + 1)
  654.  
  655.     IF modemAnswerRings = "" THEN modemAnswerRings = "1"
  656.     Message = ""
  657.     RETURN
  658.  
  659. modemFatalError:
  660. ' This routine handles modem fatal errors.
  661. ' It displays a description of the error and then gives the user the ∂
  662. ' chance to correct the problem and try again or cancel the program.
  663.  
  664.     Status = "Modem Error"
  665.     DBoxSay =  Message              ' Message contains the error
  666.     SET DBox 504
  667.     DBOX 504
  668.  
  669.     IF DBoxResult% = OK% THEN ∂     ' user selected RETRY
  670.         Message = "":∂
  671.         CLEAR DBox 504 :∂
  672.         GOSUB quickModemCommands: ∂
  673.         GOSUB modemReset: ∂
  674.         RETURN ∂
  675.     ELSE ∂                          ' user cancelled
  676.         CLEAR DBox 504: ∂
  677.         Message = "": ∂
  678.         Service = "": ∂
  679.         Network = "": ∂
  680.         CommC.RemEcho% = SaveRemEcho%: ∂    ' restore changed settings
  681.         CommC.DBits% = SaveDBits%: ∂
  682.         END
  683.  
  684. Interrupt:      ' interrupts not allowed
  685.     BELL:BELL
  686.     RETURN
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.